﻿//----------------------------------------------------

#region 命名空间

//    版权：
//    作者：
//建立时间：2012-09-11 00:00:33
//    描述：
//----------------------------------------------------
using System;
using System.Data;
using System.Text;
using System.Web.UI;
using System.Web.UI.WebControls;
using WinnerCMS.Data;
using WinnerCMS.Model;
using WinnerCMS.Common;

#endregion

namespace WinnerCMS.BLL
{
    /// <summary>
    /// 业务逻辑类 WinnerCMS_ExtensionCategories 的摘要说明。
    /// </summary>
    public class ExtensionCategoriesManage
    {
        private static readonly ExtensionCategoriesDal MyDAL = new ExtensionCategoriesDal();

        #region 添加

        /// <summary>
        /// 添加
        /// </summary>
        public void Add(ExtensionCategory model, string Action, ref string strErr)
        {
            if (model.Name.Length == 0)
            {
                strErr = "“名称”不能为空！";
                return;
            }
            if (Action == null || Action == "Add")
            {
                MyDAL.Add(model);
            }
            else
            {
                MyDAL.Edit(model);
            }
        }

        #endregion

        #region 删除

        /// <summary>
        /// 删除
        /// </summary>
        public void Delete(string IDs, UpdatePanel UpdatePanel1)
        {
            if (string.IsNullOrEmpty(IDs))
            {
                MsgBox.Message("至少选择一项。", UpdatePanel1);
            }
            else
            {
                MyDAL.Delete(IDs);
            }
        }

        #endregion

        #region 加载数据

        /// <summary>
        /// 加载数据
        /// </summary>
        public ExtensionCategory GetInfo(int ID)
        {
            return MyDAL.GetInfo(ID);
        }

        #endregion

        /// <summary>
        /// 绑定控件
        /// </summary>
        /// <param name="modelId"></param>
        /// <param name="DDL"></param>
        public void BindDll(byte modelId, DropDownList DDL)
        {
            DDL.DataSource = MyDAL.BindDLL(modelId);
            DDL.DataTextField = "Name";
            DDL.DataValueField = "ID";
            DDL.DataBind();

            DDL.Items.Insert(0, new ListItem("设为一级分类", "0"));
        }

        /// <summary>
        /// 绑定扩展分类
        /// </summary>
        /// <param name="gvList"></param>
        /// <param name="modelId"></param>
        public void BindList(BaseDataBoundControl gvList, byte modelId)
        {
            gvList.DataSource = MyDAL.BindList(modelId);
            gvList.DataBind();
        }
    }
}